package com.asdf.db.operations.companyclub;

import java.util.List;

import com.asdf.db.operations.IDBOperation;
import com.asdf.db.results.ResultStatus;
import com.asdf.db.results.companyclub.CompanyClubResult;
import com.asdf.entities.CompanyClub;

/**
 * @author so4i2014
 * Operation for finding company club.
 */
public class GetCompanyClubOp implements IDBOperation<CompanyClubResult>
{
	private List< CompanyClub> companyClubDataSource = null;
	private String companyName = null;
	
	/** Create new operation.
	 * @param source - a list to search in.
	 */
	public GetCompanyClubOp( List< CompanyClub> source)
	{
		companyClubDataSource = source;
	}
	
	/** Return the company name we are looking for.
	 * @return
	 */
	public String getCompanyName( )
	{
		return companyName;
	}

	/** Set the conpany name we are looking for.
	 * @param companyName
	 */
	public void setCompanyName( String companyName)
	{
		this.companyName = companyName;
	}

	/* (non-Javadoc)
	 * @see com.asdf.db.operations.IDBOperation#perform()
	 */
	@Override
	public CompanyClubResult perform()
	{
		CompanyClubResult result = new CompanyClubResult();
		
		result.setStatus(ResultStatus.NotFound);
		for (int i = 0; i < companyClubDataSource.size(); ++i)
		{
			if (companyClubDataSource.get(i).getCompanyName().equals(companyName))
			{
				result.setStatus(ResultStatus.OK);
				result.setCompany(companyClubDataSource.get(i));
				break;
			}
		}
		return result;
	}
}
